package Logic.dbUtils;

import Logic.constant.C;
import Logic.utils.ArrayUtilsImpl;

import java.sql.SQLException;
import java.util.List;

/**
 * @author liujun
 * @version V1.0
 * @date 2022/3/12 7:10 PM
 * @author-Email ljfirst@mail.ustc.edu.cn
 * @description
 */
public class DBTools {

    public static List<SQLTestDataEntity> getSqlResult(String className) throws SQLException {
        MySqlConnection con = new MySqlConnection();
        // List<SQLTestDataEntity> list =
        /*for (SQLTestDataEntity s : list) {
            s.print();
        }*/
        return con.execSql(C.TableName, className);
    }

    static final String s1Str = "insert into AlgorithmPracticeDB.test_data (input,output,class_name) values ('\"";
    static final String s2Str = "\"','\"";
    static final String s3Str = "\"',\"";
    static final String s4 = "\");\n";

    static final String s1IntArr = "insert into AlgorithmPracticeDB.test_data (input,output,class_name) values ('";
    static final String s2IntArr = "','";
    static final String s3IntArr = "',\"";

    public static void buildInsertSQL(String input, String output, String className) {
        String sql = s1Str + input +
                s2Str + output +
                s3Str + className + s4;
        System.out.println(sql);
    }

    public static void buildInsertSQL(int[] input, int[] output, String className) {
        String sql = s1IntArr + ArrayUtilsImpl.IntArray2Sequence(input, "[") +
                s2IntArr + ArrayUtilsImpl.IntArray2Sequence(output, "[") +
                s3IntArr + className + s4;
        System.out.println(sql);
    }
}
